/*==============================================================================
 * AUTH: Matthew Baum, 9753095
 * DATE: January-27-2012
 * EDIT: February-11-2012
 * DESC: "Static" Java class containing data processing methods.
 *==============================================================================*/

package SOEN_Phase_3;

// Import Required Data Structure Libraries
import java.util.Arrays;

public final class DataHelpers {

    // Cannot be instanciated
    private DataHelpers()
    {
        // Do nothing
    }

    // Define a "TAB" with consistent spacing
    public static final String CONST_TAB = "    ";
    public static final int CONST_TAB_WIDTH = CONST_TAB.length();

    // Print a string with N repeating characters, without building N objects
    public static String printChars(char ch, int cnt)
    {
        // Create a character buffer
        char[] char_buffer = new char[cnt];

        // Fill the buffer
        Arrays.fill(char_buffer, ch);

        // Return the resulting string
        return( new String(char_buffer) );
    }

    // Pad a string evenly with space ( ' ' ) characters
    public static String padString(String str, int padSize)
    {
        // Calculate right and left padding required
        int leftPad = 4;
        int strLen = str.length();

        // Create character buffer
        char[] paddedBuffer = new char[padSize];

        // Fill the buffer
        for(int i = 0; i != paddedBuffer.length; ++i)
        {
            // PAD LEFT
            if(i < leftPad - 1)
            {
                paddedBuffer[i] = ' ';
            }

            // COPY STRING
            else if(i < leftPad + strLen - 1)
            {
                paddedBuffer[i] = str.charAt(i - leftPad + 1);
            }

            // PAD RIGHT
            else
            {
                paddedBuffer[i] = ' ';
            }
        }

        // Return the padded string
        return( new String( paddedBuffer ) );
    }
}
